using Microsoft.AspNetCore.Mvc;
using Data.Service;
using Microsoft.AspNetCore.Http;

namespace ToDoList.Controllers
{
    public class LayoutController : Controller
    {
        InventoryService _inventoryService = new InventoryService();
        ItemService _itemService = new ItemService();
        private UserService _userService = new UserService();
        /// <summary>
        /// 获取用户名
        /// </summary>
        /// <returns></returns>
        public string GetUserName()
        {
            var user = _userService.FindUser((int)HttpContext.Session.GetInt32("userId"));
            return user.UserName;
        }
        /// <summary>
        /// 获取侧栏事项数
        /// </summary>
        /// <returns></returns>
        public int[] GetCount()
        {
            int userId = (int)HttpContext.Session.GetInt32("userId");
            var inventoryList = _inventoryService.ViewAllInventory(userId);
            var finishItemList = _itemService.GetAllFinishIteams(userId);
            var overdueItemList = _itemService.GetAllOverdueIteams(userId);
            var notFinishItemList = _itemService.GetAllNotFinishIteams(userId);
            int[] count = { inventoryList.Count, finishItemList.Count, overdueItemList.Count, notFinishItemList.Count };
            return count;
        }
    }
}
